package com.lhz.controller;

import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.lhz.pojos.DiningTable;
import com.lhz.services.DiningTableService;

@Controller
@RequestMapping("/dining")//餐桌
public class DiningTableControll {

	@Autowired
	private DiningTableService service;
	
	
	
	/**
	 * 显示餐桌
	 * @return
	 */
	@RequestMapping(value="/searchBydiningfshow")
	public ModelAndView searchByiningshow(
					@RequestParam(name="page",defaultValue="1")int pageNum,
					@RequestParam(name="rows",defaultValue="10") int pageSize) {
		ModelAndView mv=new ModelAndView();
		Map<String, Object> searchBydiningInfo = service.searchBydiningInfo(pageNum,pageSize);
		mv.addObject("showTable",searchBydiningInfo);
		mv.setViewName("diningShow");
		return mv;
	}
	/**
	 * 状态
	 * @param status
	 * @return
	 */
	@RequestMapping(value="/searchBystatus")//restful
	public ModelAndView searchBystatus(int status) {
		ModelAndView mv=new ModelAndView();
		Map<String, Object> searchBydiningInfo = service.searchByStatus(status);
		mv.addObject("showTable",searchBydiningInfo);
		mv.setViewName("diningShow");
		return mv;
	}
	
	/**
	 * 跳转餐桌添加界面
	 * @return
	 */
	@RequestMapping(value="/searchByAdddining")
	public ModelAndView searchByAdddining() {
		ModelAndView mv=new ModelAndView();
		mv.setViewName("tableAdd");
		return mv;
		
	}
	
	/**
	 * 添加
	 * @param din
	 * @return
	 */
	@RequestMapping(value="/searvhByAddtable",method=RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> searchByAddTable(DiningTable din){
		try {
			return service.searchByAddTable(din);
		} catch (Exception e) {
			e.printStackTrace();
		}
		throw new RuntimeException("添加有错误.......");
	}
	
	/**
	 * 餐桌删除
	 * @param tableName
	 * @return
	 */
	@RequestMapping(value="/delectdiningtable/{tableName}",method=RequestMethod.POST)
	@ResponseBody//采用restful参数接收风格进行代码伪造
	public Map<String,Object> delectdiningtable(@PathVariable("tableName")String tableName){
 		try {
			return service.delectdiningtable(tableName);
		} catch (Exception e) {
			e.printStackTrace();
		}
 		throw new RuntimeException("删除餐桌有错误......");
		
	}
	
	/**
	 * 修改餐桌状态
	 * @param tableName
	 * @return
	 */
	@RequestMapping(value="/upadatediningTable",method=RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> upadatediningTable(String tableName){
		try {
			return service.upadatediningTable(tableName);
		} catch (Exception e) {
			e.printStackTrace();
		}
		throw new RuntimeException("修改餐桌的状态是有错误的.....");
	}	
	
	/**
	 * 修改餐桌的属性
	 * @param tableName
	 * @param type
	 * @return
	 */
	@RequestMapping(value="/updatediningTableName",method=RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> updatediningTableName(String tableName,String type){
		try {
			return service.updatediningTableName(tableName, type);
		} catch (Exception e) {
			e.printStackTrace();
		}
		throw new RuntimeException("修改餐桌的属性是有错误出现了......");
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}
